package demo2;
//内部类

class OuterClass {
    public int data1 = 1;
    public static int data2 = 2;
    private static final int data3 = 3;
    class InnerClass {
        int data1 = 111;
        public int data4 = 4;
        private int data5 = 5;
//        private static int data6 = 6;//err
        private static final int data6 = 6;//ture 因为将其变为了常量，在编译的时候就可以完成
        public void func1() {
            System.out.println(InnerClass.this.data1);
            System.out.println(OuterClass.this.data1);
            System.out.println(OuterClass.this.data2);
            System.out.println(OuterClass.this.data3);
            System.out.println(InnerClass.this.data4);
            System.out.println(data5);
            System.out.println(data6);
        }
    }
}

class OuterClass2 {

    public void func2() {//局部内部类，很少使用
        class A {
            int a = 2;
        }
        A a = new A();
        System.out.println(a.a);
    }
    public int data1 = 10;
    private int data2 = 2;
    public static int data3 = 3;
    static class InnerClass2 {
        public int data4 = 4;
        private int data5 = 5;
        public static int data6 = 6;//因为是静态内部类 所以不用加final
        public void func() {
            OuterClass2 outerClass2 = new OuterClass2();
            System.out.println(outerClass2.data1);
            System.out.println(outerClass2.data2);
            System.out.println(data3);
            System.out.println(data4);
            System.out.println(data5);
            System.out.println(data6);
        }
    }
}

interface AA {
    void test();
}

public class TestDemo2 {
    public static void main(String[] args) {
        AA a = new AA() {
            @Override
            public void test() {
                System.out.println("重写了test()");
            }
        };
        a.test();
        System.out.println("-------");
        new AA() {
            @Override
            public void test() {
                System.out.println("重d test()");
            }
        }.test();
    }
    public static void main2(String[] args) {
        OuterClass2.InnerClass2 innerClass2 = new OuterClass2.InnerClass2();
        innerClass2.func();
        System.out.println("---------");
        new OuterClass2().func2();

    }
    public static void main0(String[] args) {
        OuterClass outerClass = new OuterClass();
//        OuterClass.InnerClass innerClass = outerClass.new InnerClass();
        OuterClass.InnerClass innerClass = new OuterClass().new InnerClass();
        innerClass.func1();
    }
}

